/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.skin.primer;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.JTextComponent;

import org.kommando.core.search.Result;
import org.kommando.skin.DialogBasedKommandoWindow;

/**
 * @author Peter De Bruycker
 */
public class PrimerKommandoWindow extends DialogBasedKommandoWindow {

    private JPanel panel;

    private Map<Selector, JLabel> selectorPanels = new HashMap<Selector, JLabel>();

    private JLabel directLabel;
    private JLabel actionLabel;
    private JLabel indirectLabel;

    @Override
    protected JComponent createDialogContent() {
        if (panel == null) {
            panel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));

            directLabel = new JLabel();
            actionLabel = new JLabel();
            indirectLabel = new JLabel();

            selectorPanels.put(Selector.DIRECT, directLabel);
            selectorPanels.put(Selector.ACTION, actionLabel);
            selectorPanels.put(Selector.INDIRECT, indirectLabel);

            panel.add(directLabel);
            panel.add(actionLabel);
            panel.add(indirectLabel);
        }

        return panel;
    }

    @Override
    public void expand() {
        indirectLabel.setVisible(true);
    }

    @Override
    public Dimension getIconSize() {
        return new Dimension(32, 32);
    }

    @Override
    public Point getSelectionListPopupPosition(Selector selector) {
        Point locationOnScreen = selectorPanels.get(selector).getLocationOnScreen();

        return new Point(locationOnScreen.x, locationOnScreen.y);
    }

    @Override
    public void shrink() {
        indirectLabel.setVisible(false);
    }

    @Override
    public void setActiveSelector(Selector selector) {
        selectorPanels.get(selector).setBackground(Color.WHITE);
    }

    @Override
    public void setSelection(Selector selector, Result<?> selection) {
        selectorPanels.get(selector).setIcon(selection == null ? null : selection.getIcon(getIconSize()));
        selectorPanels.get(selector).setText(selection == null ? null : selection.getHtmlFormattedName());
    }

    @Override
    public void setInTextMode(Selector selector, boolean inTextMode) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setTextComponent(Selector selector, JTextComponent textComponent) {
        // TODO Auto-generated method stub

    }
}
